﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Rodunu.Movies.Contracts;
using Rodunu.Movies.Interfaces.Comments;
using Rodunu.Movies.Interfaces.User;
using Rodunu.Movies.Logic.Comments;
using Rodunu.Movies.Logic.User;
using Rodunu.Movies.Web.Utility;

namespace Rodunu.Movies.Web.Controllers
{
    public class CommentsController : UserBaseController
    {
        private readonly IComments _commentsLogic;
        private readonly IUser _userLogic;

        public CommentsController()
        {
            _commentsLogic = new CommentsLogic();
            _userLogic = new UserLogic();
        }

        public void AddComment(long userMovieId, long userId, string comment, bool isLarge)
        {
            SetUser();

            if (userId == User.Id)
            {
                var comments = new Comments();
                comments.Comment = HttpUtility.UrlDecode(comment.Replace("%0A", "<br />"));
                comments.UserMovieId = userMovieId;
                comments.UserId = userId;
                comments.DateAdded = DateTime.Now;
                _commentsLogic.Create(comments);

                RenderText(userMovieId + ":::" + CommentsHelper.BuildSmallComment(comments, isLarge));
            }
        }

        public void GetComments(long userMovieId)
        {
            //IList<Comments> allcomments = _commentsLogic.GetCommentsByUserMovie(userMovieId);
            //var sb = new StringBuilder();
            //foreach (var comments in allcomments)
            //{
            //    sb.Append("<div class='SmallCommentBox'>");
            //    sb.Append(BuildSmallComment(comments));
            //    sb.Append("</div>");
            //}

            //RenderText(userMovieId + ":::" + sb.ToString());
        }

        
    }
}
